package eao;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entity.City;
import entity.User;

/**
 * Session Bean implementation class EaoUser
 */
@Stateless(mappedName = "eaoCity")
@LocalBean
public class EaoCity {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public EaoCity() {
        // TODO Auto-generated constructor stub
    }
    

    public City find(int id) {
        return em.find(City.class, id);
    }
    
    public City findByName(String city) {
    	return em.createQuery("SELECT c FROM City c WHERE c.city =:city", City.class).setParameter("city", city).getSingleResult();

    }
    
    public List<City> list() {
    	return em.createQuery("SELECT c FROM City c", City.class).getResultList();
    }

    public void create(City city) {
        	em.persist(city);
    }

    public void update(City city) {
        em.merge(city);
    }

    public void delete(City city) {
        em.remove(em.contains(city) ? city : em.merge(city));
    }
    

}
